package influence.propagation.implementation;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import influence.propagation.core.NodeModel;
import influence.propagation.core.ResultSet;
import influence.propagation.core.ResultSetBuilder;

public class BreadthResultSetBuilder implements ResultSetBuilder {
	
	private HashMap<Integer, List<NodeModel>> resultSet = new HashMap<Integer, List<NodeModel>>();
	private int state = 0;

	protected BreadthResultSetBuilder() {
		Integer i = new Integer(0);
		resultSet.put(i, new ArrayList<NodeModel>());
	}

	@Override
	public void put(NodeModel node, boolean isNewTraverse) {
		if (isNewTraverse) {
			state++;
		}
		Integer i = new Integer(state);
		List<NodeModel> tmp = resultSet.get(i);
		if (tmp == null) {
			tmp = new ArrayList<NodeModel>();
			resultSet.put(i, tmp);
		}
		tmp.add(node);
	}

	@Override
	public ResultSet getIstance() {
		return new ConcreteResultSet(resultSet);
	}

	@Override
	public void putInitialActiveNode(NodeModel node) {
		resultSet.get(new Integer(0)).add(node);
		if(state!=0){
			state = 1;
		}
	}
}
